home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / prolog / sbprolog / amiga / v3_1 / sbp3_1e.lzh / YES.PL < prev   
Text File  |  1991-10-31  |  1KB  |  44 lines

  1. /* From the book PROLOG PROGRAMMING IN DEPTH
  2.    by Michael A. Covington, Donald Nute, and Andre Vellino.
  3.    Copyright 1988 Scott, Foresman & Co.
  4.    Non-commercial distribution of this file is permitted. */
  5.  
  6. /* YES.PL */
  7.  
  8. % get1(C)
  9. %  accepts a line of input and returns only the first character.
  10. %  A good way to obtain a 1-character response from the user
  11. %  in a Prolog with buffered input, such as Quintus or ALS.
  12.  
  13. get1(C) :-
  14.   get(C),
  15.   repeat,
  16.     get0(N),
  17.     (N=10 ; N=13),
  18.   !.
  19.  
  20.  
  21. /*****************************************************
  22.  * yes(Question)                                     *
  23.  *  Displays Question, insists that the user type    *
  24.  *  Y or N (upper or lower case), and then succeeds  *
  25.  *  if user typed Y, or fails if user typed N.       *
  26.  *****************************************************/
  27.  
  28. yes(Question) :-  write(Question),
  29.                   get1(Char),
  30.                   yes_aux(Char).
  31.  
  32. yes_aux(89)   :- !.         /* Y */
  33.  
  34. yes_aux(121)  :- !.         /* y */
  35.  
  36. yes_aux(78)   :- !,fail.    /* N */
  37.  
  38. yes_aux(110)  :- !,fail.    /* n */
  39.  
  40. yes_aux(_)    :- put(7),   /* beep */
  41.                  write(' [Type Y or N]:'),
  42.                  get1(Char),
  43.                  yes_aux(Char).
  44.